﻿using System;
using System.ServiceModel;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using NotifyPilot.WCF;

namespace NotifyPilot.Test
{
    [TestClass]
    public class CoreEventsConnectorTest
    {
        private static ServiceHost _myServiceHost;

        [ClassInitialize]
        public static void InitializeClass(TestContext ctx)
        {
            _myServiceHost = new ServiceHost(typeof(CoreEventConnectors));
            _myServiceHost.Open();
        }

        [TestMethod]
        public void InvokeServiceOperation()
        {
            try
            {
                var eventXml = this.getExample(); // Use it for rapid debug/check
                var proxy = new CoreEventConnectors();
                proxy.Notify(eventXml);
                //    Assert..AreEqual<string>("Ploeh", response);
            }
            catch (Exception ex)
            {
                throw;
            }
        }

        [ClassCleanup]
        public static void CleanupClass()
        {
            _myServiceHost.Close();
        }

        private string getExample()
        {
            return @"<WorkItemChangedEvent xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance'>
  <PortfolioProject>CM-PLUS</PortfolioProject>
  <ProjectNodeId>c8691653-e096-4066-b8e4-d0e03570423e</ProjectNodeId>
  <AreaPath>\CM-PLUS\Référentiel</AreaPath>
  <Title>CM-PLUS Work Item Changed: User Story 9464 - Mettre à disposition la codification ICPE (norme DREAL) des marchandises dangereuses</Title>
  <WorkItemTitle>Mettre à disposition la codification ICPE (norme DREAL) des marchandises dangereuses</WorkItemTitle>
  <Subscriber>E-MARITIME\ScrumPilot</Subscriber>
  <ChangerSid>S-1-5-21-3079881874-1834094644-258413331-1247</ChangerSid>
  <ChangerTeamFoundationId>4a0217ad-bec2-438b-ba58-2db3fe95d378</ChangerTeamFoundationId>
  <DisplayUrl>http://192.168.239.67:8080/tfs/web/wi.aspx?pcguid=362149d5-19b0-4af2-949d-b98ef0f3a6b9&amp;id=9464</DisplayUrl>
  <TimeZone>Coordinated Universal Time</TimeZone>
  <TimeZoneOffset>00:00:00</TimeZoneOffset>
  <ChangeType>Change</ChangeType>
  <CoreFields>
    <IntegerFields>
      <Field>
        <Name>ID</Name>
        <ReferenceName>System.Id</ReferenceName>
        <OldValue>0</OldValue>
        <NewValue>9464</NewValue>
      </Field>
      <Field>
        <Name>Rev</Name>
        <ReferenceName>System.Rev</ReferenceName>
        <OldValue>0</OldValue>
        <NewValue>3</NewValue>
      </Field>
      <Field>
        <Name>Area ID</Name>
        <ReferenceName>System.AreaId</ReferenceName>
        <OldValue>0</OldValue>
        <NewValue>795</NewValue>
      </Field>
      <Field>
        <Name>Watermark</Name>
        <ReferenceName>System.Watermark</ReferenceName>
        <OldValue>0</OldValue>
        <NewValue>15151</NewValue>
      </Field>
    </IntegerFields>
    <StringFields>
      <Field>
        <Name>Work Item Type</Name>
        <ReferenceName>System.WorkItemType</ReferenceName>
        <OldValue />
        <NewValue>User Story</NewValue>
      </Field>
      <Field>
        <Name>Title</Name>
        <ReferenceName>System.Title</ReferenceName>
        <OldValue />
        <NewValue>Mettre à disposition la codification ICPE (norme DREAL) des marchandises dangereuses</NewValue>
      </Field>
      <Field>
        <Name>Area Path</Name>
        <ReferenceName>System.AreaPath</ReferenceName>
        <OldValue />
        <NewValue>\CM-PLUS\Référentiel</NewValue>
      </Field>
      <Field>
        <Name>State</Name>
        <ReferenceName>System.State</ReferenceName>
        <OldValue />
        <NewValue>Active</NewValue>
      </Field>
      <Field>
        <Name>Reason</Name>
        <ReferenceName>System.Reason</ReferenceName>
        <OldValue />
        <NewValue>New</NewValue>
      </Field>
      <Field>
        <Name>Assigned To</Name>
        <ReferenceName>System.AssignedTo</ReferenceName>
        <OldValue />
        <NewValue>c.lemerle</NewValue>
      </Field>
      <Field>
        <Name>Changed By</Name>
        <ReferenceName>System.ChangedBy</ReferenceName>
        <OldValue />
        <NewValue>Mickael Chemin</NewValue>
      </Field>
      <Field>
        <Name>Created By</Name>
        <ReferenceName>System.CreatedBy</ReferenceName>
        <OldValue />
        <NewValue>p.gerard</NewValue>
      </Field>
      <Field>
        <Name>Changed Date</Name>
        <ReferenceName>System.ChangedDate</ReferenceName>
        <OldValue />
        <NewValue>08/04/2013 08:49:28</NewValue>
      </Field>
      <Field>
        <Name>Created Date</Name>
        <ReferenceName>System.CreatedDate</ReferenceName>
        <OldValue />
        <NewValue>25/03/2013 13:15:01</NewValue>
      </Field>
      <Field>
        <Name>Authorized As</Name>
        <ReferenceName>System.AuthorizedAs</ReferenceName>
        <OldValue />
        <NewValue>Mickael Chemin</NewValue>
      </Field>
      <Field>
        <Name>Iteration Path</Name>
        <ReferenceName>System.IterationPath</ReferenceName>
        <OldValue />
        <NewValue>\CM-PLUS\v1\v1.0</NewValue>
      </Field>
      <Field>
        <Name>Authorized Date</Name>
        <ReferenceName>System.AuthorizedDate</ReferenceName>
        <OldValue />
        <NewValue>08/04/2013 08:48:40</NewValue>
      </Field>
    </StringFields>
  </CoreFields>
  <AddedRelations>
    <AddedRelation>
      <LinkName>Child</LinkName>
      <WorkItemId>9653</WorkItemId>
    </AddedRelation>
  </AddedRelations>
</WorkItemChangedEvent>";
        }

    }
}
